//
//  HYAlert.h
//  YiCuiMiaoZhang
//
//  Created by BZ on 2023/10/20.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Masonry.h"


@class HYAlertModel,HYAlertView,HYAlertActionModel;
@interface HYAlert : NSObject

/// 当前弹框模型
@property (nonatomic, strong) HYAlertModel *alertModel;

/// 当前弹框视图
@property (nonatomic, strong) HYAlertView *alertView;


/// 展示吐丝
/// - Parameter toastStr: 吐丝文本
+ (HYAlert *)showToast:(NSString *)toastStr;

/// 展示吐丝
/// - Parameters:
///   - toastStr: 吐丝文本
///   - completion: 完成回调
+ (HYAlert *)showToast:(NSString *)toastStr Completion:(void (^)(void))completion;


/// 展示吐丝
/// - Parameters:
///   - toastStr: 吐丝文本
///   - offsetCenterY: 距离中心位置垂直偏移量
+ (HYAlert *)showToast:(NSString *)toastStr OffsetCenterY:(CGFloat)offsetCenterY;

/// 展示吐丝且不自动消失
/// - Parameter toastStr: 吐丝文本
+ (HYAlert *)showToastWithoutDismiss:(NSString *)toastStr;


/// 展示普通警告框（纯文本类型）
/// - Parameter alertModel: 警告框数据模型
+ (HYAlert *)showAlertWithAlertModel:(HYAlertModel *)alertModel;


/// 展示复杂弹款，可自定义部分视图
/// - Parameters:
///   - alertModel: 弹款数据模型
///   - changeableView: 自定义视图
+ (HYAlert *)showAlertMainTemplateWithAlertModel:(HYAlertModel *)alertModel mainChangeableView:(UIView *)changeableView;


/// 标准警告框 （内容居中,底部‘取消’和‘确认’按钮）
/// - Parameters:
///   - title: 标题
///   - attributedContent: 居中富文本标题（如果是正常文本，外部用富文本转一下）
///   - cancelEvent: 取消回调
///   - confirmEvent: 确认回调
+ (HYAlert *)showAlertWithTitle:(NSString *)title AttributedContent:(NSAttributedString *)attributedContent CancelEvent:(void (^)(void))cancelEvent ConfirmEvent:(void (^)(void))confirmEvent;

/// 标准提示框 （内容富文本左对齐，底部‘我知道了’）
/// - Parameters:
///   - title: 标题
///   - attributedContent: 左对齐富文本标题（如果是正常文本，外部用富文本转一下）
///   - knowEvent: 我知道了回调
+ (HYAlert *)showRemindWithTitle:(NSString *)title AttributedContent:(NSAttributedString *)attributedContent KnowEvent:(void (^)(void))knowEvent;


/// 获取当前控制器
+ (UIViewController *)getCurrentViewController;

@end

@interface HYAlertView : UIView

/// 标题文本框
@property (nonatomic, weak) UILabel *titleLab;

/// 内容文本框
@property (nonatomic, weak) UILabel *contentLab;

/// 可变视图（不参滚动，优先空间分配）
@property (nonatomic, weak) UIView *changeableView;

/// 底部按钮视图
@property (nonatomic, weak) UIView *bottomView;


/// HYAlertView吐丝实例化方法
/// - Parameter alertModel: 弹框模型
/// - Parameter offsetCenterY: 距离中心位置垂直偏移量
- (instancetype)initWithToast:(HYAlertModel *)alertModel OffsetCenterY:(CGFloat)offsetCenterY;

/// HYAlertView实例化方法
/// - Parameters:
///   - alertModel: 弹框模型
///   - changeableView: 可变视图
- (instancetype)initWithAlertModel:(HYAlertModel *)alertModel mainChangeableView:(UIView *)changeableView;

/// 更新内容
/// - Parameter attributedContent: 富文本内容（如果是正常文本，外部用富文本转一下）
- (void)updateAttributedContent:(NSAttributedString *)attributedContent;

/// 展示吐丝且不消失
- (void)showToastWithoutDismiss;

/// 展示吐丝并自动消失
/// - Parameter completion: 完成回调
- (void)showToastDismissCompletion:(void (^)(void))completion;

/// 吐丝消失
/// - Parameter animated: 是否展示动画
- (void)dismissToastAnimated:(BOOL )animated;

/// 吐丝消失
/// - Parameters:
///   - animated: 是否展示动画
///   - completion: 完成回调
- (void)dismissToastAnimated:(BOOL )animated Completion:(void(^)(void))completion;

/// alert显示动画
- (void)showAlert;

/// alert隐藏动画
- (void)dismissAlert;

@end

@interface HYAlertCustomChangeableView : UIView


/// 创建单个勾选项可变视图
/// - Parameters:
///   - alertModel: 弹框模型
///   - title:勾选项标题
///   - selected: 勾选项是否选中
+ (UIView *)createSingleCheckBoxChangeableViewWithAlertModel:(HYAlertModel *)alertModel Title:(NSString *)title Selected:(BOOL )selected;

@end

@protocol HYAlertModelDelegate <NSObject>

- (void)alertDismissWithAlertModel:(HYAlertModel *)alertModel;

@end

@interface HYAlertModel : NSObject

/// 吐丝文本
@property (nonatomic, copy) NSString *toast;

/// 顶部标题（默认“提示”）
@property (nonatomic, copy) NSString *title;

///仅用富文本，可在外层将标准文本转为富文本
@property (nonatomic, copy) NSAttributedString *attributedContent;

/// 内容文本对其方式--默认左对齐
@property (nonatomic, assign) NSTextAlignment contentAlignment;

/// 底部按钮列表
@property (nonatomic, copy) NSArray <HYAlertActionModel *>* bottomActions;

/// 代理
@property (nonatomic, weak) id<HYAlertModelDelegate> delegate;

/// 外部changeable暂存数据，默认实例化
@property (nonatomic, strong) NSMutableDictionary *stashValue;

/// 快速构建alertMode;
/// - Parameters:
///   - title: 标题
///   - attributedContent: 富文本内容（如果是正常文本，外部用富文本转一下）
- (instancetype)initWithTitle:(NSString *)title AttributedContent:(NSAttributedString *)attributedContent;

/// 标准警告框模型对象构建 (底部取消和确认按钮)
/// - Parameters:
///   - title: 标题
///   - attributedContent: 富文本内容（如果是正常文本，外部用富文本转一下）
///   - cancelEvent: 取消回调
///   - confirmEvent: 确认回调
- (instancetype)initWithTitle:(NSString *)title AttributedContent:(NSAttributedString *)attributedContent CancelEvent:(void (^)(NSMutableDictionary *stashValue))cancelEvent ConfirmAction:(void (^)(NSMutableDictionary *stashValue))confirmEvent;

/// 提示框模型对象构建（底部我知道了按钮）
/// - Parameters:
///   - title: 标题
///   - attributedContent: 富文本内容（如果是正常文本，外部用富文本转一下）
///   - knowEvent: 我知道了回调
- (instancetype)initWithTitle:(NSString *)title AttributedContent:(NSAttributedString *)attributedContent KnowEvent:(void (^)(NSMutableDictionary *stashValue))knowEvent;

/// 创建只含一个按钮的底部按钮
/// - Parameters:
///   - actionTitle: 底部按钮标题
///   - actionEvent: 底部按钮事件
- (void)createBottomButtonArrayWithSingleActionTitle:(NSString *)actionTitle ActionEvent:(void (^)(NSMutableDictionary *stashValue))actionEvent;

/// 创建包含两个按钮的底部按钮
/// - Parameters:
///   - firstTitle: 第一个按钮标题
///   - firstEvent: 第一个按钮事件
///   - secondTitle: 第二个按钮标题
///   - secondEvent: 第二个按钮事件
- (void)creatBottomButtonArrayWithTwoActionFirstTitle:(NSString *)firstTitle FirstEvent:(void (^)(NSMutableDictionary *stashValue))firstEvent SecondTitle:(NSString *)secondTitle SecondEvent:(void (^)(NSMutableDictionary *stashValue))secondEvent;

- (void)dismissAlert;



@end



@interface HYAlertActionModel : NSObject

/// 正常文本标题
@property (nonatomic, copy) NSString *actionTitle;

/// 正常文本颜色
@property (nonatomic, copy) UIColor *titleColor;

/// 是否倒计时
@property (nonatomic, assign) BOOL timeCountDown;

/// 是否倒计时时间
@property (nonatomic, assign) NSInteger countDownNumber;

/// 倒计时标题
@property (nonatomic, copy) NSString *countDownTitle;

/// 倒计时时文本颜色
@property (nonatomic, strong) UIColor *countDownTitleColor;

/// 倒计时回调 （内部使用）
@property (nonatomic, copy) void (^timeCountDownEvent)(BOOL finish);

/// 按钮点击回调（不会主动关闭弹框） 优先级最高
@property (nonatomic, copy) void (^withoutDismissActionEvent)(NSMutableDictionary *stashValue,HYAlertView *alertView);

/// 按钮点击回调 优先级最低
@property (nonatomic, copy) void (^actionEvent)(NSMutableDictionary *stashValue);


/// 快速构建标准事件按钮
/// - Parameters:
///   - actionTitle: 按钮文本
///   - actionEvent: 按钮点击回调事件
- (instancetype)initWithActionTitle:(NSString *)actionTitle ActionEvent:(void (^)(NSMutableDictionary *stashValue))actionEvent;


/// 快速构建不会自主关闭弹框事件按钮
/// - Parameters:
///   - actionTitle: 按钮文本
///   - withoutDismissActionEvent: 不会自主关闭弹框按钮点击回调事件
- (instancetype)initWithActionTitle:(NSString *)actionTitle WithoutDismissActionEvent:(void (^)(NSMutableDictionary *stashValue,HYAlertView *alertView))withoutDismissActionEvent;

/// 快速构建包含倒计时的事件按钮
/// - Parameters:
///   - actionTitle: 按钮文本
///   - actionEvent: 按钮点击回调事件
- (instancetype)initWithTimeDownActionTitle:(NSString *)actionTitle ActionEvent:(void (^)(NSMutableDictionary *stashValue))actionEvent;


/// 倒计时开始
- (void) startTimer;



@end

